import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;


public class httpServer {

	public static void main(String args[]) {
		int port;
		ServerSocket server_socket;

		try {
			port = Integer.parseInt(args[0]);
		}catch (Exception e) {
			port = 8080;
		}
		
		try {
			server_socket = new ServerSocket(port);
			System.out.println("httpServer running on port " +
			server_socket.getLocalPort());
			while(true) {
				Socket socket = server_socket.accept();
				System.out.println("New connection accepted " +socket.getInetAddress() +":" + socket.getPort());
				try {
					httpRequestHandler request = new httpRequestHandler(socket);
					Thread thread = new Thread(request);
					thread.start();
				}catch(Exception e) {
					System.out.println(e);
				}
			}
		}catch (IOException e) {
			System.out.println(e);
		}
	}
}
